import java.util.Stack;

public class MinStack {
    private Stack<Integer> s1;
    private Stack<Integer> minStack;

    public MinStack() {
        s1 = new Stack<>();
        minStack = new Stack<>();
    }

    public void push(int val) {
        s1.push(val);
        if (minStack.empty()) {
            minStack.push(val);
        } else{
            if (val <= minStack.peek()) {
                minStack.push(val);
            }
        }
    }

    public void pop() {
        int x = s1.pop();
        int x2 = minStack.peek();
        if (s1 == minStack) {
            minStack.pop();
        }
    }

    public int top() {
        return s1.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}
